package club.mzywucai.blog.air_portal.util;

import java.util.Date;

/**
 * @author mzy
 * @Description
 * @date 2018/11/27
 */
public class DateToMsgUtil {
    // diff / 1000  // s
    // -- 刚刚(三分钟内)
    // diff / 1000 / (60*3)

    // -- xx分钟前
    // diff / 1000 / 60

    // -- xx小时前
    // --- diff / 1000 / 60 / 60

    // -- xx天前
    // -- diff / 1000 / 60 / 60 / 24

    // -- xx年前
    // -- diff / 1000 / 60 / 60 / 24 / 365
    public static String msg(Date date) {
        long time = date.getTime();
        long now = new Date().getTime();
        Integer res;
        long diff = now - time;
        if ((res = (int) (diff / 1000 / 60 / 60 / 24 / 365)) >= 1) {
            return res+"年前";
        }

        if ((res = (int) (diff / 1000 / 60 / 60 / 24)) >= 1) {
            return res+"天前";
        }

        if ((res = (int) (diff / 1000 / 60 / 60)) >= 1) {
            return res+"小时前";
        }

        if ((res = (int) (diff / 1000 / 60)) >= 3) {
            return res+"分钟前";
        }

        return  "刚刚";
    }
}
